﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPatterns
{
    public interface ICommand
    {
        void Execute();
    }

    /// <summary>
    /// 简单命令    实现命令接口
    /// </summary>
    class SimpleCommand : ICommand
    {
        private string _info;

        public SimpleCommand(string message)
        {
            this._info = message;
        }
        public void Execute()
        {
            Console.WriteLine("执行简单命令，" + _info);
        }
    }

    /// <summary>
    /// 复杂命令    实现命令接口
    /// </summary>
    class ComplexCommand : ICommand
    {
        Receiver _receiver;
        private string _complexOneInfo;

        private string _complexTwoInfo;

        public ComplexCommand(Receiver receiver, string oneInfo, string twoInfo)
        {
            _receiver = receiver;
            _complexOneInfo = oneInfo;
            _complexTwoInfo = twoInfo;
        }

        public void Execute()
        {
            Console.WriteLine("执行复杂命令");
            _receiver.DoOne(_complexOneInfo);
            _receiver.DoTwo(_complexTwoInfo);
        }
    }

    /// <summary>
    /// 接收者
    /// </summary>
    class Receiver
    {
        public void DoOne(string oneInfo)
        {
            Console.WriteLine("接收的信息为：" + oneInfo);
        }

        public void DoTwo(string oneInfo)
        {
            Console.WriteLine("接收的信息为：" + oneInfo);
        }
    }

    /// <summary>
    /// 调用者Invoker 
    /// </summary>
    public class InvokerClient
    {
        private ICommand _one;
        private ICommand _two;

        public void SetOnOne(ICommand com)
        {
            _one = com;
        }

        public void SetOnTwo(ICommand com)
        {
            _two = com;
        }

        public void DoExecute()
        {
            Console.WriteLine("调用者One的打印");
            if (_one is ICommand)
            {
                _one.Execute();
            }

            Console.WriteLine("调用者Two的打印");
            if (_two is ICommand)
            {
                _two.Execute();
            }
        }
    }

    class CommandPattern
    {
    }
}
